//
//  retweetedCell.swift
//  我的微博
//
//  Created by shmily on 15/8/3.
//  Copyright © 2015年 Stanford-IOS8-Swift-shmilyAshen. All rights reserved.
//

import UIKit

/// 有转发的微博的微博布局
class retweetedCell: HomeTableViewCell {

    //重写不会更改之前的内容
    override var status: BlogContent? {
        didSet{
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            lblRetweeted.text = "@" + name + ":" + text
        }
    }
    //重写父类方法,重新布局部分控件
    override func addControl() {
        super.addControl()
        
        //添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(lblRetweeted, aboveSubview: backButton)
        //设置布局
        //背景按钮布局
        backButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: lblContent, size: nil, offset: CGPoint(x: -homeTopViewMargin, y: homeTopViewMargin))
        backButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        //被转发内容视图布局
        lblRetweeted.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backButton, size: nil, offset: CGPoint(x: homeTopViewMargin, y: homeTopViewMargin))
        
        //图片视图,这里 size 设置任意值,为了设置约束后期修改
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: lblRetweeted, size: CGSize(width: 290, height: 290), offset: CGPoint(x: homeTopViewMargin, y: homeTopViewMargin))
        //获取 pictureView 的宽高约束
        picWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        picHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
    
    }
    
    //MARK:- 懒加载控件
    //背景按钮
    private lazy var backButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
        }()
    //原创者的信息
    private lazy var lblRetweeted: UILabel = {
        let lbl = UILabel(fontSize: 15, foreColor: UIColor.grayColor())
        lbl.numberOfLines = 0
        lbl.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * homeTopViewMargin
        return lbl
        }()
}
